package com.api.league.service.impl;

import com.api.core.service.AbstractService;
import com.api.league.dao.LeagueHighlightMapper;
import com.api.league.model.LeagueHighlight;
import com.api.league.service.LeagueHighlightService;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import tk.mybatis.mapper.entity.Condition;

import java.util.List;

/**
 * @author RenQiang
 * @date 2021/6/2
 */
@Service
@Transactional(rollbackFor = Exception.class)
public class LeagueHighlightServiceImpl extends AbstractService<LeagueHighlight> implements LeagueHighlightService {
    private final LeagueHighlightMapper leagueHighlightMapper;

    public LeagueHighlightServiceImpl(LeagueHighlightMapper leagueHighlightMapper) {
        this.leagueHighlightMapper = leagueHighlightMapper;
    }

    @Override
    public PageInfo<LeagueHighlight> findByPage(Long leagueId, Integer pageNum, Integer pageSize) {
        PageHelper.startPage(pageNum, pageSize);
        Condition condition = new Condition(LeagueHighlight.class);
        condition.createCriteria().andEqualTo("leagueId", leagueId);
        condition.orderBy("updateTime").desc();
        List<LeagueHighlight> leagueHighlights = this.findByCondition(condition);
        return new PageInfo<>(leagueHighlights);
    }
}
